<?php

class Tool_file{

 public static function url_load($_url){
  $http_page = file_get_contents($_url);
  return $http_page;
 }

 public static function file_load($_path){
  $buffer = '';
  if($id = @fopen($_path, "r")){
   $buffer = fread($id, filesize($_path));
   fclose($id);
  }
  return $buffer;
 }

 public static function file_write($_path,$_buffer){
  if($id = @fopen($_path, "w")){
   $res=fwrite($id,$_buffer);
   fclose($id);
  }
  return $res;
 }

 public static function file_add($_path,$_buffer){
  if($id = @fopen($_path, "a")){
   $res=fwrite($id,$_buffer);
   fclose($id);
  }
  return $res;
 }

 public static function file_load_csv($_path,$_sep_col,$_sep_line){
  $buffer = self::file_load($_path);
  $array = self::csv2array($buffer,$_sep_col,$_sep_line);
 }

 public static function csv2array($_data,$_sep_col,$_sep_line){
  $array_line = mb_split($_sep_line,$_data);
  $res = array();
  foreach($array_line as $num_line=>$line){
    if($line){
     $array_col = mb_split($_sep_col,$line);
     $res[$num_line] = $array_col;
    }
  }
  return $res;
 }

/*
 public static function json2array_acp($_data_json,&$_array_res){
  $js_decode=json_decode($_data_json,true);
  $entete=array_shift($js_decode);
  foreach($js_decode as $array_cmp){
    foreach($array_cmp as $id1=>$array_score){
      foreach($array_score as $id2=>$score){
        if($id2!=$id1 and !isset($_array_res["($id2.$id1)"]))
          $_array_res["($id1.$id2)"][]=$score;
      }
    }
  }
  return $entete;
 } 

 public static function array_acp2r($_array_acp){
  $count_col = count(current($_array_acp)) + 1;
  $entete = '';
  for($i = 0; $i < $count_col; ++$i){
    if($i > 0) $entete .= "$i";
    $entete .= "  ";
  }
  $entete = rtrim($entete)."\n";
  $res = '';
  foreach($_array_acp as $id=>$scores){
    $ex = implode("  ",$scores);
    $res .= "$id  ".$ex."\n";
  }
  return "$entete$res"; 
 }
*/
}

?>
